<%--
  Created by IntelliJ IDEA.
  User: J.TuTu
  Date: 2021/6/23
  Time: 18:01
  To change this template use File | Settings | File Templates.
--%>

<%@ page contentType="text/html;charset=UTF-8" language="java" pageEncoding="UTF-8" %>
<%@ page import="com.gpf.entity.Book" %>
<%@ page import="com.gpf.entity.User" %>
<%@ page import="com.gpf.service.CardService" %>
<%@ page import="com.gpf.service.impl.CardServiceImpl" %>
<html>
<head>
    <title>处理购物车</title>
</head>
<body>
<%-- 处理购物车 --%>
<%
    // 获取用户的信息
    User user =(User)session.getAttribute("user");
    // 获取书籍的信息
    Book book = (Book)session.getAttribute("book");
    // 定义购物车服务
    CardService service = new CardServiceImpl();
    // 获取图书数量且加1
    Integer booknum = service.getBookNum(book) + 1;
    // 执行添加购物车操作
    boolean flag = service.addCard(user,book,booknum);
    if(flag){
        // 添加成功返回到购物车页面
        response.sendRedirect("cart.jsp");
    }else{
        //
       response.sendRedirect("error.jsp");
    }

%>
</body>
</html>

